# /usr/bin/env python3

import json


def ModifyJSON(jsonString, **filter):
    """

   :type jsonString: string
   """
    for key, value in filter.items():
        jsonString = jsonString.replace('##' + key, value)

    return jsonString


def JsonHull(list, filter):
    f = filter.split(':')
    key = f[0]
    value = f[1]
    for num in list:
        if num[key] == value:
            return num


def FindSection(jsonString, filter, sectionName):
    data = json.loads(jsonString)
    if isinstance(data, list):
        res = JsonHull(data, filter)
        if res is not None:
            return res[sectionName]


if __name__ == '__main__':
    # test_string = 'helle##testdasdasjk'
    # filter = {"test": "hello"}
    # ModifyJSON(test_string, **filter)
    test = r'[{"DEVICETOKEN":"KNubcWzWEy3Q3fC/","IP":"192.168.1.168","REGTIME":"1531118560859","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"78A351F8BF84","ISSYNC":"1","STATUS":"1","DEVICEID":"CMCC-30103-78A351F8BF84","DEVICECLASS":"AP","LASTTIME":"1531130426692","XDATA":"{\"apUplinkType\":\"Ethernet\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceMac\":\"78A351F8BF84\",\"deviceModel\":\"L10_V11_8\",\"deviceSn\":\"78A351F8BF84\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"R607","SOFTWAREVERSION":"R2"},{"DEVICETOKEN":"kPzAv1eY0PGfoQaF","IP":"192.168.0.109","REGTIME":"1531990893632","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"7EA3513400C4","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30103-7EA3513400C4","DEVICECLASS":"AP","LASTTIME":"1532004327330","XDATA":"{\"apUplinkType\":\"Wireless\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceModel\":\"L1\",\"deviceSn\":\"12011853400C4\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rspf_503","SOFTWAREVERSION":"R110"},{"DEVICETOKEN":"ETKOIbXrS6ftrccr","IP":"192.168.0.110","REGTIME":"1533118471726","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"7EA3513401C4","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30103-7EA3513401C4","DEVICECLASS":"AP","LASTTIME":"1533118789790","XDATA":"{\"apUplinkType\":\"Wireless\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceModel\":\"L1\",\"deviceSn\":\"12011853401C4\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rspf_503","SOFTWAREVERSION":"R120"},{"DEVICETOKEN":"dsk1l0562M4FYOm6","IP":"192.168.0.104","REGTIME":"1533090691269","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"7EA3513404D8","ISSYNC":"1","STATUS":"1","DEVICEID":"CMCC-30103-7EA3513404D8","DEVICECLASS":"AP","LASTTIME":"1533090709301","XDATA":"{\"apUplinkType\":\"Wireless\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceModel\":\"L1\",\"deviceSn\":\"12011853404D8\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rspf_503","SOFTWAREVERSION":"R110"},{"DEVICETOKEN":"JvqQJ2ia9DoNQiEZ","IP":"192.168.0.103","REGTIME":"1531981149318","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"7EA3513412D0","ISSYNC":"1","STATUS":"1","DEVICEID":"CMCC-30103-7EA3513412D0","DEVICECLASS":"AP","LASTTIME":"1531981922493","XDATA":"{\"apUplinkType\":\"Wireless\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceModel\":\"L1\",\"deviceSn\":\"12011853412D0\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rspf_503","SOFTWAREVERSION":"R110"},{"DEVICETOKEN":"MwY4QqTTNvy6iOJN","IP":"192.168.0.106","REGTIME":"1531965705739","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"8AA3513404E4","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30103-8AA3513404E4","DEVICECLASS":"AP","LASTTIME":"1531965785349","XDATA":"{\"apUplinkType\":\"Wireless\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceMac\":\"8AA3513404E4\",\"deviceModel\":\"\",\"deviceSn\":\"8AA3513404E4\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rspf_503","SOFTWAREVERSION":"R84"},{"DEVICETOKEN":"qUxZvjRRyD1VhgNW","IP":"192.168.1.11","REGTIME":"1528964808824","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"E069953522AF","ISSYNC":"1","STATUS":"1","DEVICEID":"CMCC-30103-E069953522AF","DEVICECLASS":"AP","LASTTIME":"1529024232400","XDATA":"{\"apUplinkType\":\"Ethernet\",\"SyncCode\":\"0\",\"radio5\":0,\"deviceVendor\":\"CMTT\",\"deviceMac\":\"E069953522AF\",\"deviceModel\":\"L1\",\"deviceSn\":\"12011853522AF\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"Rx86","SOFTWAREVERSION":"R90"},{"DEVICETOKEN":"xnNzQ1pQYb13fe6U","IP":"192.168.8.2","REGTIME":"1533205145231","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"c2eeb50018c8","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30103-c2eeb50018c8","DEVICECLASS":"AP","LASTTIME":"1533212591331","XDATA":"{\"apUplinkType\":\"wireless\",\"SyncCode\":\"1\",\"radio5\":1,\"deviceVendor\":\"Enice\",\"deviceMac\":\"c2eeb50018c8\",\"deviceModel\":\"AN1201\",\"deviceSn\":\"EncRouter-110001172000633\"}","PRODUCTTOKEN":"1ImttzrB9t3aShra","DEVICETYPE":"30103","FIRMWAREVERSION":"cmcc-2.0.0126-rtm","SOFTWAREVERSION":"v3_1"},{"DEVICETOKEN":"riYj0A8QOG4J019X","IP":"192.168.0.106","REGTIME":"1533195613463","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"000C43768722","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30212-000C43768722","DEVICECLASS":"FatherDevice","LASTTIME":"1533195697017","XDATA":"null","PRODUCTTOKEN":"pvPBtQ12e9X1VNL7","DEVICETYPE":"30212","FIRMWAREVERSION":"null","SOFTWAREVERSION":"null"},{"DEVICETOKEN":"sg03FG/gtH3AH2dt","IP":"192.168.0.100","REGTIME":"1532928715975","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"2c3ae8189da8","ISSYNC":"1","STATUS":"0","DEVICEID":"CMCC-30405-2c3ae8189da8","DEVICECLASS":"FatherDevice","LASTTIME":"1533194041848","XDATA":"null","PRODUCTTOKEN":"hFm3pm9YBzSBsx4b","DEVICETYPE":"30405","FIRMWAREVERSION":"F1.2","SOFTWAREVERSION":"1912"},{"DEVICETOKEN":"+poED/ba54y8keGC","IP":"192.168.0.107","REGTIME":"1533263934196","PARAMDETAIL":"","PARENTDEVICEID":"null","MAC":"84f3eb8418e3","ISSYNC":"1","STATUS":"1","DEVICEID":"CMCC-30405-84f3eb8418e3","DEVICECLASS":"FatherDevice","LASTTIME":"1533263934320","XDATA":"null","PRODUCTTOKEN":"hFm3pm9YBzSBsx4b","DEVICETYPE":"30405","FIRMWAREVERSION":"F1.2","SOFTWAREVERSION":"2572"}]'
    print(FindSection(test, 'MAC:000C43768722', 'DEVICEID'))
